package 笔试;

import java.util.Scanner;

/**
 * @Date 2024/10/15 19:15
 * @description: 百度笔试
 * .
 * @Author LittleNight
 */
public class baidu {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int k = in.nextInt();
            if(n == 1) {
                System.out.println(1);
            }else if(k > n/2 ) {
                System.out.println(n%2==0 ? n / 2 : n / 2 + 1);
            }else {
                System.out.println(n/2);
            }
            // int[] f = new int[n + 1]; // 选第i个
            // int[] g = new int[n + 1]; // 不选第i个
            // f[1] = 1; g[1] = 0;
            // for(int i = 2; i <= n; i++) {
            //     f[i] = g[i - 1] + 1;
            //     g[i] = Math.max(f[i - 1], g[i - 1]);
            // }
            // int ret = Math.max(f[n], g[n]);
            // System.out.println(ret);
        }
    }

    public static void main22(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            if(n <= 3) {
                System.out.println(0);
            }
            if(n == 4) {
                System.out.println(10);
            }
//            if(n==5) {
//                System.out.println(10 * 5);
//            }else if(n == 6) System.out.println(10 * 15);
//            else if(n == 7) System.out.println(10 * 35);
//            else if(n == 8) System.out.println(10 * 70);
//            else if(n == 9) System.out.println(10 * 126);
//            else if(n == 10) System.out.println(10 * 210);
//            else if(n == 11) System.out.println(10 * 330);
//            else if(n == 12) System.out.println(10 * 495);
//            else if(n == 13) System.out.println(10 * 715);
        }
    }

    public static void main11(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String s = in.next();
            int n = s.length();
            String ret = s;
            for (int i = 0; i < n; i++) {
                ret = move(ret, i + 1);
            }
            System.out.println(ret);
        }
//        System.out.println(move("abcde", 5));
    }
    // 写一个函数. 可以指定将一个字符串的第i位转移到最后面
    public static String move(String s, int i){
        char[] chars = s.toCharArray();
        if(i == 1) {
            char tmp = chars[0];
            return s.substring(1, chars.length) + tmp;
        }else if(i == s.length()) {
            return s;
        }else {
            char temp = chars[i-1];
            for (int j = i-1; j < chars.length - 1; j++) {
                chars[j] = chars[j+1];
            }
            chars[chars.length-1] = temp;
            return String.valueOf(chars);
        }
    }
}
